package com.leetcode.algorithm.y22.m06;

import com.leetcode.algorithm.common.ListNode;

/**
 * 206. 反转链表
 * 
 * https://leetcode.cn/problems/reverse-linked-list/
 * 
 * @author jie.deng
 *
 */
class Question0206Solution01 {

	public ListNode reverseList(ListNode head) {
		if (head == null || head.next == null) {
			return head;
		}
		ListNode listNode = reverseList(head.next);
		appendTail(listNode, new ListNode(head.val));
		return listNode;
	}

	private void appendTail(ListNode head, ListNode listNode) {
		if (head.next == null) {
			head.next = listNode;
		}
		appendTail(head.next, listNode);
	}

}